package rldungeon.help

import net.cyndeline.scalarlib.rldungeon.dgs.graph.{PointlessAreaData, Room}
import net.cyndeline.scalarlib.rldungeon.grammar.util.VertexFactory
import net.cyndeline.scalarlib.rlgraph.subgraph.isomorphism.ElementEquivalence
import scalax.collection.immutable.Graph

/**
 * Vertex instance usable in tests.
 */
class TestVertex(val string: String, val int: Int) extends Room[TestVertex](int, 0, None, false) {
  override def toString: String = "<" + string + "|" + int + ">"

  def withDistanceToGoal(d: Int): TestVertex = ???
  def withPointlessData(data: PointlessAreaData[TestVertex]): TestVertex = ???
  def withPointlessStatus(pointless: Boolean): TestVertex = ???
  def canHoldAdditionalRewards: Boolean = ???
  def canHoldAdditionalActivators: Boolean = ???
  def isStart: Boolean = ???
  def isGoal: Boolean = ???

  override def equals(o: Any): Boolean = o match {
    case t: TestVertex => t.string == string && t.int == int
    case _ => false
  }

  override def hashCode: Int = string.## ^ int.##
}

/**
 * Factory to test productions with.
 * @param vertices Vertices to be produced if custom vertices are needed.
 */
class TestVertexFactory(vertices: TestVertex*) extends VertexFactory[TestVertex] {
  var verticesToProduce = vertices.toVector
  var customProductions = false

  if (!vertices.isEmpty) {
    customProductions = true
  }

  var i = 0

  def produce: TestVertex = {
    if (customProductions) {
      val result = verticesToProduce.head
      verticesToProduce = verticesToProduce.drop(1)
      result
    } else {
      i += 1
      new TestVertex("Blabla", i)
    }
  }
}

/**
 * Compares two vertices based on their int value.
 */
class IntEquivalence extends ElementEquivalence[TestVertex, CorridorEdge] {
  def compares(e1: TestVertex, e2: TestVertex, contextForE1: Graph[TestVertex, CorridorEdge], contextForE2: Graph[TestVertex, CorridorEdge]): Boolean = e1.int == e2.int
  def elementHash(element: TestVertex): Int = element.int.##
}
